<template>
  <div class="service-area">
    <div class="header">
      <div class="total-num">{{serviceArea.parkingcount}}</div>
      <div class="total">总泊位数</div>
      <div class="percent">
        <ul class="left">
          <li>{{serviceArea.spackcount}}</li>
          <li>空泊车数</li>
        </ul>
        <ul class="middle">
          <li>{{serviceArea.utilization}}%</li>
          <li>利用率</li>
        </ul>
        <ul class="right">
          <li>{{serviceArea.free}}%</li>
          <li>占用率</li>
        </ul>
      </div>
    </div>
    <div class="line"></div>
    <div class="center">
      <h2>服务区</h2>
      <div class="item" v-for="(item,index) in serviceAreaList" :key="index" @click="goTo(item.serviceAreacode)">
        <h3>{{item.serviceAreaname}}</h3>
        <div class="left">
          <span class="text">总泊位</span>
          <span class="num">{{item.parkingcount}}</span>
        </div>
        <div class="right">
          <span class="text">空泊位</span>
          <span class="num red">{{item.spackcount}}</span>
        </div>
      </div>
    </div>
  </div>

</template>

<script>
import { getallserviceArea } from './../../../api'
export default {
  name: 'ServiceArea',
  data () {
    return {
      // 所有服务区信息
      serviceArea: {},
      // 服务区详情
      serviceAreaList: []
    }
  },
  created () {
    // 获取服务区信息
    this.getAllServiceAreaData()
  },
  methods: {
    goTo (item) {
      // 点击跳转到服务区详情页时携带编号id
      // console.log(item)
      this.$router.push(`/count/servicearea/detail?id=${item}`)
    },
    // 获取服务区信息函数
    async getAllServiceAreaData () {
      const res = await getallserviceArea()
      this.serviceArea = res.data
      this.serviceAreaList = res.data.serviceAreaList
    }
  }
}
</script>

<style scoped lang="less">
  .service-area {
    margin-top: 37px;

    .header {
      overflow: hidden;

      .total-num {
        text-align: center;
        font-size: 45px;
        color: #fffffd;
        margin-bottom: 19px;
      }

      .total {
        text-align: center;
        color: #fff;
        font-size: 12px;
        letter-spacing: 1px;
        margin-bottom: 26px;
      }

      .percent {
        overflow: hidden;
        padding: 0 15px;
        position: relative;
        margin-bottom: 14px;

        .left, .middle, .right {
          float: left;
          color: #fff;
          text-align: center;
          letter-spacing: 1px;

          li:nth-child(1) {
            font-size: 18px;
            margin-bottom: 15px;
          }

          li:nth-child(2) {
            font-size: 12px;
          }
        }

        .right {
          float: right;
        }

        .middle {
          position: absolute;
          top: 22px;
          left: 50%;
          transform: translate(-50%, -50%);
        }
      }
    }

    .line {
      height: 15px;
      width: 100%;
      background-color: #f5f5f6;
    }

    .center {
      background-color: #fff;
      height: auto;
      h2 {
        padding: 15px 0 0 15px;
        font-size: 17.5px;
        color: #2f2f2f;
        font-weight: 600;
        letter-spacing: 1px;
      }
      .item {
        margin: 0 15px;
        padding: 15px 0;
        height: 100px;
        background-color: #fff;
        border-bottom: 1px solid #e5e5e5;
        &:nth-child(n+2){
          height: 70px;
        }
        &:last-child{
          border-bottom: none;
        }

        h3 {
          font-size: 15px;
          color: #848484;
          margin-bottom: 14px;
        }

        .left {
          float: left;

          .text {
            font-size: 12px;
            color: #989898;
            margin-right: 30px;
          }

          .num {
            font-size: 15px;
            color: #323232;
          }
        }

        .right {
          float: right;
          .text {
            font-size: 12px;
            color: #989898;
            margin-right: 30px;
          }

          .num {
            font-size: 15px;
            color: #ee4b34;
          }
        }
      }
    }
  }
</style>
